/*
 * Copyright 2007-2009 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.paoding.rose.web.var;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import net.paoding.rose.web.impl.thread.InvocationBean;

/**
 * 仅仅提供Rose框架使用
 * 
 * @author qieqie.wang@paoding.net
 * 
 */
public class PrivateVar {

	private static ThreadLocal<HttpServletRequest> requestHolder = new ThreadLocal<HttpServletRequest>();

	private static ServletContext servletContext;

	public static void servletContext(ServletContext sc) {
		servletContext = sc;
	}

	public static ServletContext servletContext() {
		return servletContext;
	}

	public static void request(HttpServletRequest request) {
		requestHolder.set(request);
	}

	public static HttpServletRequest request() {
		return (HttpServletRequest) requestHolder.get();
	}

	public static HttpSession session() {
		return session(true);
	}

	public static HttpSession session(boolean create) {
		return request().getSession(create);
	}

	public static void setInvocation(InvocationBean invocation) {
		request().setAttribute("$$paoding-rose.invocation", invocation);
	}

	public static InvocationBean getInvocation() {
		return (InvocationBean) request().getAttribute(
				"$$paoding-rose.invocation");
	}
}
